<template>
  <div>
    <el-form ref="ruleForm" :model="tag" label-width="100px">
      <el-form-item label="标签名称" prop="tagName">
        <el-input v-model="tag.tagName" />
      </el-form-item>
      <el-form-item label="标签颜色" prop="tagColor">
        <el-color-picker
          v-model="tag.tagColor"
          :show-alpha="false"
          color-format="hex"
          :predefine="predefineColors"
        />
      </el-form-item>
      <el-form-item label="提交" label-width="100px">
        <el-button type="primary" @click="updateTag()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import tagApi from '../../../api/tag'

export default {
  name: 'TagUpdate',
  props: {
    tag: {
      tag: Object,
      default: null
    }
  },
  data() {
    return {
      predefineColors: [
        '#ff4500',
        '#ff8c00',
        '#ffd700',
        '#90ee90',
        '#00ced1',
        '#1e90ff',
        '#c71585',
        'rgba(255, 69, 0, 0.68)',
        'rgb(255, 120, 0)',
        'hsv(51, 100, 98)',
        'hsva(120, 40, 94, 0.5)',
        'hsl(181, 100%, 37%)',
        'hsla(209, 100%, 56%, 0.73)',
        '#c7158577'
      ]
    }
  },
  methods: {
    updateTag() {
      tagApi.update(this.tag).then(res => {
        if (res.code === 200) {
          this.$emit('getTagList')
          this.$emit('closeUpdateDialog')
          this.$message.success(res.msg)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
